package com.anbang.website.service;

import java.util.Map;

import com.anbang.website.utils.HttpClientUtil;
import com.anbang.website.utils.HttpRequest;

import net.sf.json.JSONObject;

public class ServiceHelper {

	public static JSONObject get(String svr_, Map<String, Object> paramMap) {
		String params = JSONObject.fromObject(paramMap).toString();
		return get(svr_, params);
	}

	public static JSONObject get(String svr_, String params) {
		HttpRequest req = new HttpRequest();
		req.setMethod(HttpRequest.METHOD_GET);
		req.setUrl(svr_);
		req.setJsonParams(params);
		String ret = HttpClientUtil.execute(req);
		JSONObject jsonObj = JSONObject.fromObject(ret);
		return jsonObj;
	}

	
	public static JSONObject post(String svr_, Map<String, Object> paramMap) {
		String params = JSONObject.fromObject(paramMap).toString();
		return post(svr_, params);
	}

	public static JSONObject post(String svr_, String params) {
		HttpRequest req = new HttpRequest();
		req.setMethod(HttpRequest.METHOD_POST);
		req.setUrl(svr_);
		req.setJsonParams(params);
		String ret = HttpClientUtil.execute(req);
		JSONObject jsonObj = JSONObject.fromObject(ret);
		return jsonObj;
	}
}
